package com.sgb.kjwl.viewmodel.self.website;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.self.WebsiteQualityEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.websiteManage.WebsiteQualifiActivity3;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WebsiteRequalityModel3 extends BaseViewModel {

    private WebsiteQualifiActivity3 activity;
    private SelfRepertory repertory;
    private int page = 1;
    private int pageSize = 20;

    public WebsiteRequalityModel3(WebsiteQualifiActivity3 activity3, SelfRepertory tr){
        this.activity = activity3;
        this.repertory = tr;
    }

    public void getQualityListData(String id){
        DialogHelper.showProgressDialog(activity, null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getMailListAPI().getWebsiteQuality(id,page+"",pageSize+"").enqueue(new Callback<BaseEntity<ProListEntity<List<WebsiteQualityEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ProListEntity<List<WebsiteQualityEntity>>>> call, Response<BaseEntity<ProListEntity<List<WebsiteQualityEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.showQualityList(response.body().getData().getList());
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ProListEntity<List<WebsiteQualityEntity>>>> call, Throwable t) {
                t.printStackTrace();
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
